<script setup>
import { onMounted, ref } from 'vue';
import FooterComponent from '../Footer.vue';
import { useRoute } from "vue-router";
import axios from "axios";
import {  baseURL } from '../apis/homeAPI';

const route = useRoute();
const achievement = ref(null);

const fetchAchievement = async () => {
  const id = route.params.id;
  try {
    const response = await axios.get(baseURL + `/api/industry-dynamics/${id}?populate=*`);
    console.log(response.data); // 输出 API 响应数据

    const data = response.data.data.attributes;
    const imageUrl = data.image?.data?.attributes?.url;

    achievement.value = {
      title: data.title,
      time: data.time,
      imageUrl: imageUrl ? baseURL + `${imageUrl}` : null,
      descriptionOne: data.descriptionOne,
      descriptionTwo: data.descriptionTwo
    };
  } catch (error) {
    console.error('Error fetching achievement:', error);
  }
};

onMounted(() => {
  fetchAchievement();
});
</script>

<template>
  <div class="page-wrapper">
    <div class="header-banner">
      <div class="header-content">
        <h1 class="header-title">行业动态</h1>
        <a-breadcrumb class="breadcrumb" v-if="achievement">
          <a-breadcrumb-item><a href="/" class="breadcrumb-link">首页</a></a-breadcrumb-item>
          <a-breadcrumb-item><router-link to="/ID" class="breadcrumb-link">行业动态</router-link></a-breadcrumb-item>
          <a-breadcrumb-item class="breadcrumb-link">{{ achievement.title }}</a-breadcrumb-item>
        </a-breadcrumb>
      </div>
    </div>
    <div class="container">
      <div class="industry-news" v-if="achievement">
        <h1>{{ achievement.title }}</h1>
        <p class="date">{{ achievement.time }}</p>
        <img :src="achievement.imageUrl" alt="行业动态图片" class="industry-news-image" /><br>
        <p class="description">{{ achievement.descriptionOne }}</p>
        <p class="description">{{ achievement.descriptionTwo }}</p>
      </div>
    </div>
    <FooterComponent />
  </div>
</template>

<style scoped>
/* 保持你的样式不变 */
body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f4f4f4;
}

.page-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header-banner {
  width: 100%;
  height: 500px; /* 根据需要调整高度 */
  background: url('../images/33.jpg') no-repeat center center;
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.header-content {
  text-align: center;
  color: #ffffff;
  padding: 20px;
  border-radius: 10px;
}

.header-title {
  margin: 0;
  font-size: 3em;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  position: relative;
  color: #ffffff; /* 设置字体颜色为白色 */
}

.header-title::after {
  content: '';
  display: block;
  width: 100px;
  height: 3px;
  background: red;
  margin: 10px auto 0;
}

.breadcrumb {
  display: inline-block;
  margin-top: 10px;
}

.breadcrumb .breadcrumb-link {
  color: #BFDDE0;
  font-size: 1.2em;
}

.breadcrumb .breadcrumb-link:hover {
  text-decoration: underline;
}

.container {
  width: 80%;
  margin: auto;
  overflow: hidden;
  padding: 20px;
  flex: 1;
}

.industry-news {
  background: #fff;
  margin: 20px 0;
  padding: 30px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

.industry-news h1 {
  font-size: 2.5em;
  color: #29627e;
  margin-bottom: 10px;
  text-align: center;
  position: relative;
  font-weight: bold;
}

.industry-news h1::after {
  content: '';
  display: block;
  width: 100px;
  height: 3px;
  background: #29627e;
  margin: 10px auto 0;
}

.industry-news .date {
  font-size: 1em;
  color: #999;
  text-align: center;
  margin-bottom: 20px;
}

.industry-news p {
  font-size: 1.2em;
  color: #666;
  line-height: 1.6em;
  margin-bottom: 20px;
}

.industry-news p strong {
  color: #333;
}

.industry-news-image {
  width: 100%;
  max-width: 1000px;
  height: auto;
  margin-top: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.description {
  text-indent: 2em; /* 首行缩进 */
  line-height: 1.8em; /* 行高 */
  color: #444; /* 更深的颜色 */
  font-size: 1.1em; /* 适中的字体大小 */
}

footer {
  margin-top: auto; /* 确保页脚位于页面底部 */
}
</style>
